import request from "@/utils/request";
// 获取所有菜单
type Common<T> = {
    code: string,
    data: T, //T表示任意类型any
    message: string,
    time: string
}
// Common表示保存的具体数据类型
export type MenuItem={
    createdBy: string
    createdTime: string
    description: string
    href: string
    icon: string
    id: number
    level: number                //菜单级别
    name: string
    operatorId: number | null   //联合类型可能是数值也可能是null
    orderNum: number            //顺序
    parentId: number            //父一级层级
    shown: boolean
    updatedBy: string
    updatedTime: string
}
//定义创建或编辑菜单的所需类型1、partial表示可以不传，2、pick表示只取其中几个属性(要哪个属性拿哪个属性),3、omit表示去掉其中几个属性,4、record表示键值对
// export type CreateOrEditMenu=Partial<MenuItem> 
export type CreateOrEditMenu=Pick<MenuItem,'name'|'href'|'parentId'|'description'|'icon'|'shown'|'orderNum'>&{id?: number}
// export type CreateOrEditMenu=Omit<MenuItem,'createdBy'|'createdTime'|'level'|'description'|'icon'|'shown'|'orderNum'> 
// export type CreateOrEditMenu=Pick<MenuItem,'name'|'href'|'parentId'|'description'|'icon'|'shown'|'orderNum'> 

// 获取所有菜单逻辑
export const getAll=()=>{
    return request<Common<MenuItem[]>>({
        method:'GET',
        url:'/boss/menu/getAll',
        
    })
}


// 创建或编辑菜单的逻辑
export const saveOrUpdateMenu=(menuInfo:CreateOrEditMenu)=>{
    return request<Common<boolean>>({
        method:'POST',
        url:'/boss/menu/saveOrUpdate',
        data:menuInfo
    })
}
// 删除菜单逻辑(调用删除接口，实现功能)
export const deleteMenu=(id:MenuItem['id'])=>{
    return request<Common<boolean>>({
        method:'DELETE',
        url:`/boss/menu/${id}`,
    })
}
